package com.atguigu.gmall.order.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
@Slf4j
public class RabbitmqConfig {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void init(){
        //消息到达队列失败
        rabbitTemplate.setReturnCallback((message,replyCode,replyText,exchange,routingKey)->{
            log.error("消息到达队列失败, replyCode:{} , replyText:{} , exchange:{} , routingkey:{}, messge:{}"
                ,replyCode,replyText,exchange,routingKey,new String(message.getBody()));
        });
        //消息到达交换机的状态
        rabbitTemplate.setConfirmCallback((correlationData,ack,cause)->{
            if(!ack){
                log.error("消息到达交换机失败,cause：{}" , cause);
            }
        });
    }

}
